/**
 *
 */
package com.biotecan.genome.cytobandviewer.data;

import java.util.ArrayList;
import java.util.List;

/**
 * @author SuFeng
 *
 */
public class Chromosome implements java.io.Serializable {

    /**
     * serialVersionUID
     */
    private static final long serialVersionUID = 4944737767050264887L;
    private String chrName;
    private int chrIndex;
    private long start;
    private long end;
    private long length;
    private List<Cytoband> bands = new ArrayList<>();

    private List<Mutation> mutations = new ArrayList<>();
    
    
    /**
     * @return the chrName
     */
    public String getChrName() {
        return chrName;
    }

    /**
     * @param chrName the chrName to set
     */
    public void setChrName(String chrName) {
        this.chrName = chrName;
    }

    /**
     * @return the chrIndex
     */
    public int getChrIndex() {
        return chrIndex;
    }

    /**
     * @param chrIndex the chrIndex to set
     */
    public void setChrIndex(int chrIndex) {
        this.chrIndex = chrIndex;
    }

    
    /**
     * @return the start
     */
    public long getStart() {
        return start;
    }

    /**
     * @param start the start to set
     */
    public void setStart(long start) {
        this.start = start;
    }

    /**
     * @return the end
     */
    public long getEnd() {
        return end;
    }

    /**
     * @param end the end to set
     */
    public void setEnd(long end) {
        this.end = end;
    }

    /**
     * @return the bands
     */
    public List<Cytoband> getBands() {
        return bands;
    }

    /**
     * @param bands the bands to set
     */
    public void setBands(List<Cytoband> bands) {
        this.bands = bands;
    }

    public long getLength() {
        if (length <= 0) {
            length = this.end < 0 ? 0 : this.end - this.start < 0 ? 0 : this.start;
        }
        return length;
    }

    public void setLength(long length) {
        this.length = length;
    }

    public List<Mutation> getMutations() {
        return mutations;
    }

    public void setMutations(List<Mutation> mutations) {
        this.mutations = mutations;
    }

  

    
    public void addMutation(Mutation mutation){
        mutations.add(mutation);
    }
    
    public static String convertChromosomeIndexToName(int i) {
        // TODO Auto-generated method stub
        StringBuilder sb = new StringBuilder();
        sb.append("chr");
        if (i == 23) {
            sb.append("X");
        } else if (i == 24) {
            sb.append("Y");
        } else {
            sb.append(i);
        }
        return sb.toString();
    }

    public static int convertChromosomeNameToIndex(String chromosome) {
        int chromosomeNumber;
        if (chromosome.equalsIgnoreCase("chr1")) {
            chromosomeNumber = 1;
        } else if (chromosome.equalsIgnoreCase("chr2")) {
            chromosomeNumber = 2;
        } else if (chromosome.equalsIgnoreCase("chr3")) {
            chromosomeNumber = 3;
        } else if (chromosome.equalsIgnoreCase("chr4")) {
            chromosomeNumber = 4;
        } else if (chromosome.equalsIgnoreCase("chr5")) {
            chromosomeNumber = 5;
        } else if (chromosome.equalsIgnoreCase("chr6")) {
            chromosomeNumber = 6;
        } else if (chromosome.equalsIgnoreCase("chr7")) {
            chromosomeNumber = 7;
        } else if (chromosome.equalsIgnoreCase("chr8")) {
            chromosomeNumber = 8;
        } else if (chromosome.equalsIgnoreCase("chr9")) {
            chromosomeNumber = 9;
        } else if (chromosome.equalsIgnoreCase("chr10")) {
            chromosomeNumber = 10;
        } else if (chromosome.equalsIgnoreCase("chr11")) {
            chromosomeNumber = 11;
        } else if (chromosome.equalsIgnoreCase("chr12")) {
            chromosomeNumber = 12;
        } else if (chromosome.equalsIgnoreCase("chr13")) {
            chromosomeNumber = 13;
        } else if (chromosome.equalsIgnoreCase("chr14")) {
            chromosomeNumber = 14;
        } else if (chromosome.equalsIgnoreCase("chr15")) {
            chromosomeNumber = 15;
        } else if (chromosome.equalsIgnoreCase("chr16")) {
            chromosomeNumber = 16;
        } else if (chromosome.equalsIgnoreCase("chr17")) {
            chromosomeNumber = 17;
        } else if (chromosome.equalsIgnoreCase("chr18")) {
            chromosomeNumber = 18;
        } else if (chromosome.equalsIgnoreCase("chr19")) {
            chromosomeNumber = 19;
        } else if (chromosome.equalsIgnoreCase("chr20")) {
            chromosomeNumber = 20;
        } else if (chromosome.equalsIgnoreCase("chr21")) {
            chromosomeNumber = 21;
        } else if (chromosome.equalsIgnoreCase("chr22")) {
            chromosomeNumber = 22;
        } else if (chromosome.equalsIgnoreCase("chrX")) {
            chromosomeNumber = 23;
        } else if (chromosome.equalsIgnoreCase("chrY")) {
            chromosomeNumber = 24;
        } else {
            chromosomeNumber = 0;
        }
        return chromosomeNumber;
    }

    @Override
    public String toString() {
        return "Chromosome{" + "chrName=" + chrName + ", chrIndex=" + chrIndex + ", start=" + start + ", end=" + end + ", length=" + length + ", bands=" + bands + '}';
    }
    
    
}
